Skip to content

fix(storage): S3 chunked uploads resolve their object key from the upload session row - #31705

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-lhttwr
Nov 8, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-lhttwr

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #31607

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:S3 分片上传的分片门与完成门在调用后端前,从持久的 sys_upload_session.key 取对象 key 交给适配器;可替换存储代理补上 setUploadKey 转发。
  • 为什么改:经代理时适配器的进程内 uploadId→key 表从未被填,单副本上第 0 片就 500;这张表只在一个进程里,换副本必然找不到。
  • 风险与回滚:只动 S3 适配器经过的路径;本地适配器与无 setUploadKey 的适配器调用不变(各一个 pin)。回滚即 revert 本 PR,无数据迁移。
  • 先看:storage-routes.ts(handUploadKeyToBackend 及分片门、完成门两处调用)、swappable-storage-service.ts(setUploadKey 转发)、新测试 s3-chunked-upload-session-key.test.ts。
  • 两分钟验证:pnpm --filter @objectstack/service-storage exec vitest run src/s3-chunked-upload-session-key.test.ts,预期 4/4 通过;在 main 上同一文件两个 S3 用例 500 失败。
  • 需要你做的:无,席位落地。

What changes

  • storage-routes.ts: a new module helper handUploadKeyToBackend(storage, uploadId, key) hands the backend the object key of a chunked upload. The chunk door and the completion door call it with session.key (the sys_upload_session row each door already reads) right before uploadChunk / completeChunkedUpload. The init door no longer calls setUploadKey itself: every backend call that names the upload now gets the key from the row, on whichever process serves it.
  • swappable-storage-service.ts: the proxy forwards setUploadKey to the active adapter, and is a no-op for an adapter without it (same pattern as the proxy's existing verifyToken and getPresignedUploadOrigin passthroughs). This is what made chunk 0 fail on a single replica: the kernel's storage service is the proxy, and the init door's 'setUploadKey' in storage probe never matched it.
  • s3-storage-adapter.ts, attachment-lifecycle.ts: comments only. They described the map as filled once by the plugin, and said the proxy does not forward setUploadKey. Both were made false by this change. No code change in either file.
  • .changeset/31607-s3-chunked-upload-session-key.md: @objectstack/service-storage patch.

No change to the IStorageService contract (packages/spec), to the chunked-upload HTTP requests or answers, to sys_upload_session (it already stores key, a required field), or to the local adapter (it records the key beside its parts at initiation).

Why the row, not a new key-taking method on the adapter: the card prefers the durable row, and the row already holds the key, so no column is added. Handing it down through the existing setUploadKey keeps a single way to address an upload on the adapter; the upload-session reap guard already re-seeds the same map from the same row before an abort, so the chunk and completion doors now follow that precedent. No new public name is introduced on the package entry; the proxy gains one method that the S3 adapter already had.

Tests

New file packages/services/service-storage/src/s3-chunked-upload-session-key.test.ts (4 cases). It drives the real doors (registerStorageRoutes) through SwappableStorageService, the way StorageServicePlugin composes them, against an S3-compatible stand-in. Like S3, the stand-in refuses a part, completion or abort addressed to an UploadId under a different key (NoSuchUpload).

  • completes on a single replica: init, chunk 0, chunk 1 and completion through one proxy and one S3 adapter; the bucket holds the whole file and no multipart is left open.
  • resumes on a fresh adapter instance: another process finds the key in the session row: three replicas (separate adapter instances behind separate proxies) share one metadata store and one bucket. Init runs on A, chunk 0 on B, chunk 1 and completion on C. The object lands under the session row's key and the file row is committed.
  • local: the assembled file holds the bytes sent, across two adapter instances on one root: unchanged behaviour for the local adapter.
  • an adapter with no setUploadKey receives exactly the contract calls, with the arguments it did before: an in-memory adapter double sees the same four calls with the same arguments as on main.

A new file, not a new describe in an existing harness: the S3 stand-in is a vi.mock of @aws-sdk/client-s3, which is file-scoped, and no existing file mocks S3 and mounts the routes together. No existing test was changed.

Step 0: the defect on main (5d1382a), new file against the unfixed code
[5xx] 500 — S3StorageAdapter: key not found for uploadId. Call setUploadKey() before uploadChunk().
     × completes on a single replica
     × resumes on a fresh adapter instance: another process finds the key in the session row
AssertionError: {"success":false,"error":{"code":"INTERNAL","message":"Internal error"}}: expected 500 to be 200
      Tests  2 failed | 2 passed (4)

sys_upload_session fields written by the init door: id (= the backend UploadId when the backend initiated), file_id, key (required), filename, mime_type, total_size, chunk_size, total_chunks, resume_token, backend_upload_id, scope, bucket, metadata, status, expires_at; the chunk door adds parts, uploaded_chunks, uploaded_size. The object key is present, so no column is needed.

Ablations (scripts/ablation-replace.mjs, restore proven blob == HEAD and git diff HEAD empty)

The test imports ./storage-routes.js and ./swappable-storage-service.js relatively, so vitest runs src; no dist leg applies.

  1. Back to the in-process table: the init door seeds the map once through the proxy (ABLATION-INIT-SEED, count 1) and the chunk and completion doors no longer hand down the row's key (ABLATION-NO-ROW-KEY, count 2, anchor 2 → 0). Only the second-process case goes red, with the original error:
    [5xx] 500 — S3StorageAdapter: key not found for uploadId. Call setUploadKey() before uploadChunk().
         × resumes on a fresh adapter instance: another process finds the key in the session row
          Tests  1 failed | 3 passed (4)
    ablation-replace: ok restored: blob == HEAD (8e21af92d37b) and `git diff HEAD` is empty
    
  2. The proxy drops the key (ABLATION-PROXY-DROPS-KEY, anchor 1 → 0). Both S3 cases go red:
         × completes on a single replica
         × resumes on a fresh adapter instance: another process finds the key in the session row
          Tests  2 failed | 2 passed (4)
    ablation-replace: ok restored: blob == HEAD (a5b6010fb8eb) and `git diff HEAD` is empty
    

Acceptance notes

  • The S3 adapter's map still gains an entry on every process that serves a chunk, and only the process that completes or aborts the upload deletes its entry. An upload abandoned before completion already left its entry behind on main. The entries are small and are not a record anything trusts, since the row is the record. Noted, not filed.
  • The upload-session reap guard (createUploadSessionReapGuard) still reaches the inner adapter through getInner() to seed the key before an abort. That still works, and the proxy now forwards the call too. It was left as is so that its tests are not changed.

Verification

All on head 14e4eea9.

  • pnpm --filter @objectstack/service-storage build && … test && … typecheck under the lock: VERDICT command-exit 0; Test Files 76 passed (76), Tests 1428 passed (1428); check:test-typecheck OK.
  • Lint: root eslint --no-inline-config packages/services/service-storage/src (the package has no lint script), exit 0.
  • Derived gate families: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack listed 73; all 73 ran after turbo run build --filter='./packages/**' --filter='./examples/**' (VERDICT command-exit 0), every one exit 0. --ran reconciliation: 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN.
  • Dogfood, targeted (no ! in the title, no (narrowing) arm, so the full battery is CI's): storage-chunked-parallel-parts, storage-chunked-resume-integrity, attachments-permission-matrix, error-sentences-live under the lock: VERDICT command-exit 0; Test Files 4 passed (4), Tests 37 passed, 1 skipped (38). These run the local adapter, so they show the local path unchanged; the S3 path is covered by the new unit file.
  • origin/main moved 12 commits past the base 5d1382a5; none touches packages/services/service-storage, so no merge was taken.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (packages/spec untouched.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes (root eslint --no-inline-config over packages/services/service-storage/src, exit 0).
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 section is the lane's Chinese summary for the maintainer).
  • The Before Submitting list in CONTRIBUTING.md is done.

Card thread session: session_01ADHkmRmL5ZWYTvnS9e3kmo (dev, domain:server#4).

🤖 Generated with Claude Code

https://claude.ai/code/session_01ADHkmRmL5ZWYTvnS9e3kmo


Generated by Claude Code

…on row

The chunk and completion doors hand sys_upload_session.key to the backend
before every call, and the swappable proxy forwards setUploadKey, so an S3
chunked upload no longer fails on chunk 0 behind the proxy and a chunk or
completion served by another process finds its key.

Claude-Session: https://claude.ai/code/session_01ADHkmRmL5ZWYTvnS9e3kmo
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/service-storage, touching 11 documentable anchor(s).

3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/plugin-endpoints.mdx (via initChunkedUpload (sdk, the bare tail of client method storage.initChunkedUpload, bound to POST /api/v1/storage/upload/chunked), storage.initChunkedUpload (sdk, the route ledger binds it to POST /api/v1/storage/upload/chunked))
  • content/docs/kernel/contracts/storage-service.mdx (via uploadChunk (symbol, a method of class S3StorageAdapter))
  • content/docs/kernel/runtime-services/storage-service.mdx (via initChunkedUpload (sdk, the bare tail of client method storage.initChunkedUpload, bound to POST /api/v1/storage/upload/chunked))
What this run could not see
  • the SDK route bridge reached 65 of 231 client-bound route-ledger rows — the other 166 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 166: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 107 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json e81636ce7ed9161e759076556871ab73d3aac4cd → packageMentionDocs.

Which tree this was computed on

This run read content/docs from da7a9c081b4186b6d94aa057432133cb525321a9 — the merge of head 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d into base e81636ce7ed9161e759076556871ab73d3aac4cd, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin da7a9c081b4186b6d94aa057432133cb525321a9 && git checkout da7a9c081b4186b6d94aa057432133cb525321a9
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e81636ce7ed9161e759076556871ab73d3aac4cd 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d && git checkout -B drift-repro e81636ce7ed9161e759076556871ab73d3aac4cd && git merge --no-ff 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d

node scripts/docs-audit/affected-docs.mjs --json e81636ce7ed9161e759076556871ab73d3aac4cd

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs e81636ce7ed9161e759076556871ab73d3aac4cd → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#4 · os-steve · session_01ADHkmP8JJo4zF2sjTBRwnX

ACCEPT · PR #31705 · #31607 · 2026-11-08T22:52Z

Head-sha: 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d

  • Seat review (TIER_DEFAULT; Clause-②: no, Metadata-protocol: none; no contract face is hit, so no contract-review record is owed): the chunk and completion doors hand sys_upload_session.key (the durable record the init door already writes, the same key it passes to initiateChunkedUpload) to the backend before every uploadChunk / completeChunkedUpload, so a request on any process finds the key. SwappableStorageService forwards setUploadKey to the active adapter, a no-op without it. Dropping the init-door setUploadKey call is safe because every later door hands the key down again. The local adapter and adapters without setUploadKey are unchanged (two pins). No HTTP shape, spec or column change. Right.
  • Open question (os-dev-report 6727764572), ruled A as implemented: keep setUploadKey seeded from the row; no new key-taking adapter methods.
  • Surface: claim 6727402867 (packages/services/service-storage/src/**) covers every file in the diff. The proxy lives in swappable-storage-service.ts, not attachment-lifecycle.ts as the claim's parenthesis guessed, and is inside the claimed glob; no breach.
  • Tests and ablations: s3-chunked-upload-session-key.test.ts covers a single S3 replica, three fresh adapters (a second process), and the local and no-setUploadKey controls. Reverting to the in-process map turns only the second-process case red; dropping the proxy forward turns both S3 cases red; both were restored. After the merge round on this head: service-storage 1428/1428, typecheck OK.
  • Prose face (TIER_DEFAULT): the changeset says who is affected (S3 chunked uploads, POST /storage/upload/chunked), that the doors read the key from sys_upload_session.key and the proxy forwards the call, and that local adapters, HTTP shapes and migrations are unchanged, each matching the diff. The comment corrections in s3-storage-adapter.ts and attachment-lifecycle.ts match the code.
  • Gates on this head: check-runs success 35, skipped 15, no failure, none in progress. check-governed-merges --pr 31705: not governed, +374/-17 (Tier S). K = 4 (< 15).
  • Landing: pr_ready + automerge_enable in this stroke. Card closes on merge (Fixes #31607).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 8, 2026 22:52
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 8, 2026 22:52
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit e43a169 Nov 8, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-lhttwr branch November 8, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(storage): S3 chunked upload fails with 'key not found for uploadId' behind the swappable storage proxy

1 participant